#include "RenderComponent.h"
#include "MeshNode.h"

SceneNodePtr BaseRenderComponent::GetSceneNode()
{
	if(m_SceneNode == SceneNodePtr())
	{
		m_SceneNode = CreateSceneNode();
	}
	return m_SceneNode;
}
SceneNodePtr MeshRenderComponent::CreateSceneNode()
{
	TransformComponent* transform = m_pOwner->GetComponent<TransformComponent>(TransformComponent::m_ComponentType);
	if(transform == NULL)
	{
		return SceneNodePtr();
	}
	SceneNodePtr node(RE_NEW MeshNode(transform->m_ToWorld));
	MeshNode* n = dynamic_cast<MeshNode*>(node.get());
	n->m_pMesh = m_pMesh;
	n->m_pMaterial = m_pMaterial;
	n->m_Props.m_ActorId = m_pOwner->VGetId();
	return node;
}
const ComponentType MeshRenderComponent::m_ComponentType = "MeshRenderComponent";
const ComponentType BaseRenderComponent::m_BaseComponentType = "BaseRenderComponent";